// pages/song-playlist/index.js

import {
  APIMusic
} from "../../service/api_music"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    palyList: [],
    type: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const type = options.type
    this.setData({
      type
    })

    this.getPageData(type)
  },

  getPageData(type) {
    if (type === 'hot') {
      APIMusic.getHotSongMenu(1, 40).then(res => {
        this.setData({
          palyList: res.playlists
        })
      })
    }

    if (type === 'recommend') {
      APIMusic.getRecommendMenu(40).then(res => {
        this.setData({
          palyList: res.result
        })
      })
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },


  // 点击歌单跳转到歌曲列表页面
  handlePlaylistClick(event) {
    const id = event.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/songs-detail/index?id=${id}&type=menu`,
    })
  }
})